
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>收货地址</title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">
		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
		<script src="html5plus://ready"></script>
		<script src="../../js/ajax.js"></script>
		<script src="../../js/area.js"></script>
		<script type="text/javascript" src="../../js/fanhui.js" ></script>
	</head>
	<body>
		<div id="app">
			<header>
				<van-nav-bar @click-left="onClickLeft" style="background-color: red;">
					<van-icon slot="left" name="arrow-left" color="white"></van-icon>
					<label slot="title" style="color: white;">收货地址</label>
					<label slot="right" style="color: white;">删除</label>
				</van-nav-bar>
			</header>
			<section>
				<van-row>
					<van-address-edit :area-list="areaList" show-delete show-set-default show-search-result :search-result="searchResult"
					 @save="onSave" @delete="onDelete" @change-detail="onChangeDetail" change-default="default"></van-address-edit>
				</van-row>
			</section>
			<footer>
			</footer>
		</div>
	</body>
	<script>
		var vm = new Vue({
			el: "#app",
			data: {
				areaList: address, //省市区的数据
				searchResult: [],
				user: [] //储存用户的所有信息
			},
			methods: {
				onClickLeft: function() { //返回个人中心
					plus.webview.close(plus.webview.currentWebview(), "slide-out-left");
				},
				onSave(val) { /*点击保存按钮时触发*/
					ajax({//添加收获地址
						url: "http://dsapi.ysd3g.com/API/AddShippingAddress",
						dataType: "jsonp",
						data: {
							name:val.name,
							phone:val.tel,
							key:vm.user.Key,
							districtCode:val.areaCode,
							address:val.addressDetail,
							isdefault:val.isDefault
						},
						success: function(res) {
							if(res.Error)
							{
								vm.$toast(res.Msg);
								return;
							}
							vm.$toast("添加成功!");
						}
					});
				},
				onDelete() { //确认删除地址时触发
					$.toast('delete');
				},
				onChangeDetail(val) { //修改详细地址时触发--val	详情地址内容
					if (val) {
						this.searchResult = [{
							name: '安阳职业技术学院',
							address: '9号教学楼'
						},
						{
							name: '中所屯社区',
							address: '6号楼'
						},
						{
							name: '中所屯社区',
							address: '7号楼'
						},
						];
					} else {
						this.searchResult = [];
					}
				},
				default: function() { //地址设为默认地址的时候

				} 
			},
			created: function() {
				this.user = JSON.parse(plus.storage.getItem("user"));
				console.log(this.user);
			}
		});
	</script>
</html>
